// pages/personal/perplan2.js
var util = require('../../utils/util');
var that;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    barimages: ['../../images/bnav1h.png', '../../images/bnav2n.png', '../../images/bnav3n.png','../../images/bnav4n.png'],
    pro: '0%',
    recordurl: '../../images/ic_record.png',
    playbtn:'../../images/ic-play.png',
    week:1,
    step:1,
    title:'锻炼',
    weekTitle:'锻炼',
    percent:'0',
    videoList:[],
    hidden:true,
    videoSrc: "https://sv.baidu.com/videoui/page/searchresult?pd=alading&loc=http%3A%2F%2Fwww.internal.video.baidu.com%2F9656b7d401e1c3d65e15e3b563a39f81.html&srcid=4185&lid=15167290436243505474&log_loc=http%3A%2F%2Fv.qq.com%2Fx%2Fpage%2Fb0387ql0tvy.html&query=健身视频教程",
    autoplay:false,
    videoWidht:'100%',
    videoHeight:'300'

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this;
    // TODO 修改问卷调查状态
    // util.sendRequest("WXUpdateQuestionState", { isOk: 0 });
    wx.getSystemInfo({
      success: function(res) {
        that.setData({videoHeight:res.windowWidth});
      },
    });
    util.sendRequest('WxGetNowStep',{},function(resp){

      that.setData({ week: resp.result.week,step: resp.result.step, title: resp.result.title, percent: resp.result.percent, weekTitle: resp.result.weekTitle});
      
      util.sendRequest('WxGetVideoList', { week: resp.result.week, step: resp.result.step}, function (resp) {

        for (var i = 0; i < resp.result.length; i++) {
          resp.result[i].costMinute = Math.floor(resp.result[i].time / 60);
        }
        //
        that.setData({ videoList:resp.result });
      }, '加载中...', function () {

      });

    },'加载中...',function(){

    });
  },
  hideVideo:function(){
    that.setData({ hidden: true });
    var videoContext = wx.createVideoContext('myVideo');
    videoContext.pause();
  },
  cf: function () {
    wx.redirectTo({
      url: '/pages/index/index',
    })
  },
  toMine:function () {
    wx.redirectTo({
      url: '/pages/personal/percenter',
    })
  },
  playVideo:function(e){
    var objid = e.currentTarget.dataset.objid;
 
    util.sendRequest('WxGetVideDetail', { id: objid}, function (resp) {

      // 视频地址
      that.setData({ videoSrc: resp.result.videUrl, hidden: false, autoplay:true });
      var videoContext = wx.createVideoContext('myVideo');
      videoContext.play();
    }, '加载中...', function () {

    });
  },
  toLog:function(){
      wx.navigateTo({
        url: '/pages/personal/exerecord',
      })
  },
  startNow:function(){
    wx.setStorageSync('tempWeek', that.data.week);
    wx.setStorageSync('tempStep', that.data.step);
      wx.navigateTo({
        url: '/pages/function/warm-up1',
      })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return util.getShareMsg();
  }
})